// Transport.cpp: implementation of the CTransport class.
//
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4530)
#include "Transport.h"

#ifdef IPV6_SUPPORT
#include "SIPHeader.h"
#endif

#ifdef USE_DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTransport::CTransport(CSIPStack* pStack, const mystring& ip, uint16 port)
{
	m_nType = Unknown;
	m_pSIPStack = pStack;
#ifdef IPV6_SUPPORT
	if(is_ipv6_address(ip.c_str()))
	{
		m_strLocalIP = "[";
		m_strLocalIP += ip;
		m_strLocalIP += "]";
	}else
#endif
		m_strLocalIP = ip;
	m_nLocalPort = port;
	m_bRunning = false;
	m_hRecvThread = 0;
	m_hSendThread = 0;
}

CTransport::~CTransport()
{
	if(m_bRunning)
	{
		m_bRunning = false;
		if(m_hSendThread)
		{
			pthread_join(m_hSendThread,NULL);
			m_hSendThread = 0;
		}
		if(m_hRecvThread)
		{
			pthread_join(m_hRecvThread,NULL);
			m_hRecvThread = 0;
		}
	}
}

void * CTransport::RecvProc(void *argc)
{
	CTransport *pt = (CTransport *)argc;
	pt->DoRecv();
	return 0;
}

void * CTransport::SendProc(void *argc)
{
	CTransport *pt = (CTransport *)argc;
	pt->DoSend();
	return 0;
}
